perf: use ValueListBuilder in GetInternal#4309
perf: use ValueListBuilder in GetInternal#4309TimothyMakkison wants to merge 1 commit intothomhurst:mainfrom
ValueListBuilder in GetInternal#4309Conversation
6d0d335 to
f3ad607
Compare
SummaryThis PR optimizes Critical Issues1. Merge Conflict with PR #4308 🚨This PR is based on code before PR #4308 was merged. PR #4308 (commit 8b189a0) completely restructured This PR will revert all of PR #4308's work if merged as-is. Required action: Rebase this PR on the latest 2. Unsafe Cast to Listvar attributes = (List<Attribute>)testContext.Metadata.TestDetails.GetAllAttributes();This cast is brittle and relies on internal implementation details. Why it matters: The PR author notes this avoids Suggested fix: Remove the cast and iterate over Suggestions
Verdict |
f3ad607 to
41685e1
Compare
|
Sorry, I had made this change a while back but was waiting to #4310. IMO this is easier to read than #4307 and faster as this doesn't enumerate each collection twice, nor does it allocate the enumerators for
I agree this isn't fantastic, I've added a |
SummaryThis PR optimizes BuildEligibleEventObjects by using ValueListBuilder to reduce allocations. Critical Issues1. Complete Rewrite - Will Revert PR #4308This PR completely deletes TestContextExtensions.cs (331 lines with caching infrastructure from PR #4308) and replaces it with 61 lines. This removes all the event receiver caching added in PR #4308. Required: Rebase on latest main and apply ValueListBuilder optimization only to BuildEligibleEventObjects (line 165), keeping all caching logic intact. 2. Unsafe Cast to ListThe cast (List)GetAllAttributes() is fragile. GetAllAttributes returns IReadOnlyList which happens to be a List today, but could change. The micro-optimization (~40 bytes) is not worth the brittleness risk. Suggested fix: Remove cast, iterate over IReadOnlyList directly. Previous Review StatusMaintainer already identified merge conflict. Author acknowledged waiting to rebase. VerdictREQUEST CHANGES:
Note: The ValueListBuilder optimization itself is sound and will be beneficial once applied to the correct version. |
Use
ValueListBuilderinGetInternalto reduce allocations.AppendIfNotNullmethod toVLBValueListBuilderis initialised with the pre calculated capacity (VLBwill rent an array of at least that size)nullvalues.nullare added we don't need theOfType<null>call inGetEligibleEventObjectsor the redundantToArraycallinjectedPropsif it contains values to avoid allocating aConcurrentDictionary.Enumeratorattributesto beList<Attribute>to preventList<Attribute>.EnumeratorallocationWhy does
_cachedAllAttributesexist? We initialiseTestDetailswithAttributesByTypewhich is constructed from a list of all the attributes - we then recalculate this via_cachedAllAttributes. Why not just pass this in?Before
After